package com.rd.student.jiaji.class1.lixin;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

public class Random1 {
    public static List<String> getRandomStudents(Set<String> students, int n) {
        List<String> randomStudents = new ArrayList<>();
        List<String> studentList = new ArrayList<>(students);
        Random random = new Random();

        while (randomStudents.size() < n && !studentList.isEmpty()) {
            int index = random.nextInt(studentList.size());
            String student = studentList.get(index);
            randomStudents.add(student);
            studentList.remove(index);
        }

        return randomStudents;
    }

    public static void main(String[] args) {
        Set<String> students = new HashSet<>();
        students.add("石睿");
        students.add("杜雨坤");
        students.add("黄奕鸣");
        students.add("金洪宇");
        students.add("李鑫");
        students.add("王宇芳");
        students.add("苏岩");

        // 添加更多学生名字...

        int n = 5; // 随机抽取学生人数
        List<String> randomStudents = getRandomStudents(students, n);

        System.out.println("随机抽取的" + n + "个同学：");
        for (String student : randomStudents) {
            System.out.println(student);
        }
    }
}


